import { Column, Entity, Tree, TreeChildren, TreeParent } from 'typeorm';
import { DBColumns } from '../';
import { AreaSchema } from '../../schema';

@Entity('area')
@Tree('closure-table')
export class Area extends DBColumns implements AreaSchema {
  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '区域编码',
  })
  code: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '区域名称',
  })
  name: string;

  @Column({
    type: 'int',
    nullable: false,
    default: null,
    comment: '区域成绩',
  })
  level: number;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: false,
    default: null,
    comment: '父级区域编码',
  })
  pCode: string;

  @TreeParent()
  parent?: AreaSchema;

  @TreeChildren()
  children?: AreaSchema[];
}
